﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

using USS.Service.ValueObject;

namespace USS.Web.Controllers
{
    /// <summary>
    /// 管理控制器基类
    /// </summary>
    public class BaseController : Controller
    {
        /// <summary>
        /// 输出对象
        /// 默认结果为成功标识
        /// </summary>
        protected JRSMessage msg = new JRSMessage(Constants.SUCCESS);

        /// <summary>
        /// 获取指定名称的请求参数值
        /// </summary>
        /// <param name="name">参数名称</param>
        /// <returns>对应参数值</returns>
        protected string RequestParam(string name)
        {
            return string.IsNullOrEmpty(""+Request[name]) ? "" : Request[name].Trim();
        }

        /// <summary>
        /// 验证是否为有效参数
        /// 规则:参数字符长度大于0
        /// </summary>
        /// <param name="arg">参数</param>
        /// <returns>是否有效</returns>
        public static bool IsValid(string arg)
        {
            if (arg.Length > 0)
            {
                return true;
            }
            return false;
        }

        /// <summary>
        /// 验证是否为有效参数组
        /// </summary>
        /// <param name="args">参数组</param>
        /// <returns>是否有效</returns>
        public static bool IsValid(string[] args)
        {
            bool isValid = true;
            foreach (string item in args)
            {
                if (!IsValid(item))
                {
                    isValid = false;
                    break;
                }
            }
            return isValid;
        }
    }
}
